﻿using System.Linq;
using System.Web.Mvc;
using mtg_trader.Core.Search;
using mtg_trader.Database;
using mtg_trader.Web.Models.Home;

namespace mtg_trader.Web.Controllers
{
    public class AdministrationController : Controller
    {
        //
        // GET: /Administration/

        public ActionResult Index(string cardName = null)
        {
            return View();
        }

        //public ActionResult Card(string cardName)
        //{
        //    if (string.IsNullOrEmpty(cardName)) RedirectToAction("Index");
        //    using (var context = new MtgContext())
        //    {
        //        var cards = context.Cards.FirstOrDefault(c => c.Name == cardName);
        //        var sets = context.Sets.Where(s => s.Cards.Any(c => c.Name == cardName));
        //        var model = new CardModel(cards, sets);
        //        return View("Card", model);
        //    }
        //}

        public JsonResult Autocomplete(string query)
        {
            return Json(MagicCards.QuickCardList(query).ToArray(),
                        JsonRequestBehavior.AllowGet);
        }

    }
}
